<?php
//var_dump($this->data['RolePrivilege'][1][0]);
if (count($roles>0)){?>  

    <div class="row-fluid" >
        
        <div class="span12">
            <div class="span9">
                <h1><?php echo '<h1>' ;

                    echo $this->Html->link(h($project['Project']['name']),'view/'.$project['Project']['id']);
                ?>

                </h1>
        
            </div>
            <?php echo $this->element('members/addRole')?>
            
        </div>
    </div>
    <br/><br/><br/>
<?php
    echo $this->Form->create('RolePrivilege',array('url' => '../projects/role/'.$this->params['pass'][0], 'class'=>'form-horizontal')); 

//    var_dump($roles);
    ?>  
    

    <table class="table table-hover">
        <thead>
            <tr>
                <th>Rol</th>
                <?php
                foreach ($roles[0]['Privilege'] as $priv){
                        echo '<th>'.$priv['description'].'</th>';
                }
                ?>
            </tr>
        </thead>
        <tbody>
            <?php
            $i=0; 
            foreach ((array)$roles as $r){
                echo '<tr>';
                echo '<td>'.$r['Role']['description'].'</td>';
                $j=0;
                foreach ($r['Privilege'] as $priv){
                     echo '<td>';
                     echo $this->Form->input($i.']['.$j.'][role_id', array('type' => 'hidden','value'=>$priv['RolePrivilege']['role_id']));
                     echo $this->Form->input($i.']['.$j.'][privilege_i', array('type' => 'hidden','value'=>$priv['RolePrivilege']['privilege_i']));
                    if ($priv['RolePrivilege']['state']) $ch='checked="checked"';
                    else $ch="";
                   ?>
                    
                    <input type="radio" name="data[RolePrivilege][<?php echo $i;?>][<?php echo $j;?>][state]" id="ProjectMemberState<?php  echo $priv['RolePrivilege']['role_id'].'1'; ?>" value="1" <?php  echo $ch; ?>> S
                   <?php 
                    if (!$priv['RolePrivilege']['state']) $ch='checked="checked"';
                    else $ch="";
                   ?>
                   
                    <input type="radio" name="data[RolePrivilege][<?php echo $i;?>][<?php echo $j;?>][state]" id="ProjectMemberState<?php  echo $priv['RolePrivilege']['role_id'].'0'; ?>" value="0" <?php  echo $ch; ?>> N
                   <?php
//                   if ($priv['RolePrivilege']['state'])
//                                echo '<td>1</td>';
//                            else
//                                echo '<td>0</td>';
                    echo '</td>';
                    $j++;
                }
                echo '</tr>';
                $i++;
            }
        ?>
        </tbody>
    </table>
    <?php //
  /*  foreach ($roles as $r){
        echo $r['Role']['description'].'<br/>';
        foreach ($r['Privilege'] as $priv){
            echo $priv['Privilege'].':';
                    if ($priv['RolePrivilege']['state'])
                        echo '1<br/>';
                    else
                        echo '0<br/>';
        }
    }
*/

            $options = array(
                            'label' => 'Guardar','class' => 'btn'
                        );
                        echo $this->Form->end($options);
                    
}?>